package com.baiyang.server.service.base.impl;


import com.baiyang.server.model.system.Resource;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.system.ResourceService;
import com.baiyang.server.tools.DataTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.base.GoodsDao;
import com.baiyang.server.model.base.Goods;
import com.baiyang.server.service.base.GoodsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class GoodsServiceImpl extends BaseServiceImpl<GoodsDao, Goods> implements GoodsService{
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private ResourceService resourceService;

    /**
     * 插入新增的商品信息
     * 1.插入基本信息
     * 2.插入资源信息
     * @param goods
     */
    @Override
    @Transactional
    public void insertGood(Goods goods) {
        goods.setLaveNum(goods.getGoodNum());
        goodsDao.insert(goods);
        Resource resource = new Resource();
        resource.setId(DataTool.createUUID());
        resource.setRelationId(goods.getId());
        resource.setRelationType("pic");
        resource.setPath(goods.getPic());
        resource.setType("pic");
        resource.setCreateBy(goods.getCreateBy());
        resourceService.insert(resource);
    }
}
